//
//  LinePhotoView.m
//  DongDongWedding
//
//  Created by 谢曦 on 16/8/11.
//  Copyright © 2016年 gl. All rights reserved.
//

#import "LineBrowseView.h"

#define  kMargin  5
#define  kTopBarH  44
@interface LineBrowseView ()


@property (nonatomic,copy) NSString *cellIdentifier;


@end

@implementation LineBrowseView
-(void)awakeFromNib{
    [super awakeFromNib];
    [self collectionView];
    _cellIdentifier=@"cell";
    
}
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
       
        [self collectionView];
       
      _cellIdentifier=@"cell";
           }
    return self;
}




#pragma mark -UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
{
    return self.dataArr.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
//    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_cellIdentifier forIndexPath:indexPath];
    self.LineBrowseViewConfigureCell?self.LineBrowseViewConfigureCell(cell,indexPath):nil;
  
    return cell;
    
    
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  _cellSize;
}


-(void)registerCellWithClass: (Class )cellClass reuseIdetifier:(NSString *)reuseIdetifier
{
  [_collectionView registerClass:[cellClass class] forCellWithReuseIdentifier:reuseIdetifier];
    _cellIdentifier=reuseIdetifier;

}
-(void)registerCellWithNib:(nullable UINib *)nib reuseIdetifier:(NSString *)reuseIdetifier
{
       [self.collectionView registerNib:nib
                                   forCellWithReuseIdentifier:reuseIdetifier];
    _cellIdentifier=reuseIdetifier;
}
#pragma mark - getter and setter

-(void)setDataArr:(NSArray *)dataArr
{
    _dataArr=dataArr;
    [self.collectionView reloadData];

}

-(UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        _cellSize=layout.itemSize;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 10;
        layout.sectionInset=UIEdgeInsetsMake(kMargin, kMargin, kMargin, kMargin);
       _collectionView = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollsToTop = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        
//         [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
//        [self registerCellWithClass:[UICollectionViewCell class] reuseIdetifier:@"cell"];
        [self addSubview:_collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        
        }];

    }
    return _collectionView;
}

@end
